package org.gingresosapi.persistencia;

import org.gingresosapi.beans.Vehiculoshipoteca;
import java.sql.Date; 
import org.gingresosapi.beans.*;
import org.gingresosapi.controller.*;
import java.io.Serializable;
import java.util.List;
import java.util.ArrayList;
import java.util.*;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.util.Map;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Map;
 import javax.sql.DataSource;
import org.gingresosapi.generales.Mensajeria;
import org.gingresosapi.generales.DataGManager;


/**
*
* @author
*/

public class VehiculoshipotecaPersistencia implements Serializable {
private static final long serialVersionUID = 1L;
public static Exception excepcion;
public static boolean esMensaje = false;
public static Connection con = null;
public static java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/gingresosapi/properties/mensajes");
static DataGManager dataGManager;
static List<Vehiculoshipoteca> list;

public VehiculoshipotecaPersistencia(){
         esMensaje =false;
}


/**
*
* insert()
*/

public static boolean insert (Vehiculoshipoteca vehiculoshipoteca ) {
  excepcion = null;
  try {
      esMensaje =false;
   
   
   

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pinsert = null;
      String sql = "insert into vehiculoshipoteca(idvehiculo,placa,idrecibo,fechahipoteca,identidad,activo,idmunicipio,fecha,username,idreciboliberacion,fechahipotecaliberacion,idvehicleshipoteca)  values(?,?,?,?,?,?,?,?,?,?,?,?)";
      pinsert = con.prepareStatement(sql);
              pinsert.setLong(1,vehiculoshipoteca.getIdvehiculo());
        pinsert.setString(2,vehiculoshipoteca.getPlaca());
        pinsert.setInt(3,vehiculoshipoteca.getIdrecibo());
        pinsert.setDate(4,vehiculoshipoteca.getFechahipoteca());
        pinsert.setInt(5,vehiculoshipoteca.getIdentidad());
        pinsert.setString(6,vehiculoshipoteca.getActivo());
        pinsert.setString(7,vehiculoshipoteca.getIdmunicipio());
        pinsert.setDate(8,vehiculoshipoteca.getFecha());
        pinsert.setString(9,vehiculoshipoteca.getUsername());
        pinsert.setInt(10,vehiculoshipoteca.getIdreciboliberacion());
        pinsert.setDate(11,vehiculoshipoteca.getFechahipotecaliberacion());
        pinsert.setInt(12,vehiculoshipoteca.getIdvehicleshipoteca());
      int filas= pinsert.executeUpdate();
      pinsert.close();
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
 }


/**
*
* update()
*/

public static boolean update(Vehiculoshipoteca vehiculoshipoteca ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update vehiculoshipoteca set  idvehiculo=?, placa=?, idrecibo=?, fechahipoteca=?, identidad=?, activo=?, idmunicipio=?, fecha=?, username=?, idreciboliberacion=?, fechahipotecaliberacion=?, idvehicleshipoteca=?  where  idvehicleshipoteca ='"+vehiculoshipoteca.getIdvehicleshipoteca()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setLong(1,vehiculoshipoteca.getIdvehiculo());
pupdate.setString(2,vehiculoshipoteca.getPlaca());
pupdate.setInt(3,vehiculoshipoteca.getIdrecibo());
pupdate.setDate(4,vehiculoshipoteca.getFechahipoteca());
pupdate.setInt(5,vehiculoshipoteca.getIdentidad());
pupdate.setString(6,vehiculoshipoteca.getActivo());
pupdate.setString(7,vehiculoshipoteca.getIdmunicipio());
pupdate.setDate(8,vehiculoshipoteca.getFecha());
pupdate.setString(9,vehiculoshipoteca.getUsername());
pupdate.setInt(10,vehiculoshipoteca.getIdreciboliberacion());
pupdate.setDate(11,vehiculoshipoteca.getFechahipotecaliberacion());
pupdate.setInt(12,vehiculoshipoteca.getIdvehicleshipoteca());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* update()
*/

public static boolean update(String sqlupdate ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update  vehiculoshipoteca set " + sqlupdate +"";
      pupdate= con.prepareStatement(sql);
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* updatePrimaryKey()
*/

public static boolean updatePrimaryKey(Vehiculoshipoteca vehiculoshipoteca_old , Vehiculoshipoteca vehiculoshipoteca) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update vehiculoshipoteca set  idvehicleshipoteca=?  where  idvehicleshipoteca ='"+vehiculoshipoteca_old.getIdvehicleshipoteca()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setInt(12,vehiculoshipoteca.getIdvehicleshipoteca());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(Vehiculoshipoteca vehiculoshipoteca ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from vehiculoshipoteca  where  idvehicleshipoteca = ?  ";
      pdelete= con.prepareStatement(sql);
      pdelete.setInt(12,vehiculoshipoteca.getIdvehicleshipoteca());
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(String sqldelete ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from vehiculoshipoteca where " + sqldelete +"";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* deleteAll()
*/

public static boolean deleteAll() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from vehiculoshipoteca  ";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodeleteall"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* exists()
*/



public static boolean exists(Vehiculoshipoteca vehiculoshipoteca) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      String sql = "select * from vehiculoshipoteca where idvehicleshipoteca='"+vehiculoshipoteca.getIdvehicleshipoteca()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculoshipoteca" +" " + bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return false;
   }
    rs.close();
    psquery.close();
 return true;
} catch (Exception ex) {
      excepcion = ex;
}
  return false;
}


/**
*
* findByPrimaryKey()
*/



public static Vehiculoshipoteca findByPrimaryKey(Vehiculoshipoteca vehiculoshipoteca) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      String sql = "select * from vehiculoshipoteca where idvehicleshipoteca='"+vehiculoshipoteca.getIdvehicleshipoteca()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculoshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
            
            
            vehiculoshipoteca.setIdvehiculo(rs.getLong("idvehiculo"));
vehiculoshipoteca.setPlaca(rs.getString("placa"));
vehiculoshipoteca.setIdrecibo(rs.getInt("idrecibo"));
vehiculoshipoteca.setFechahipoteca(rs.getDate("fechahipoteca"));
vehiculoshipoteca.setIdentidad(rs.getInt("identidad"));
vehiculoshipoteca.setActivo(rs.getString("activo"));
vehiculoshipoteca.setIdmunicipio(rs.getString("idmunicipio"));
vehiculoshipoteca.setFecha(rs.getDate("fecha"));
vehiculoshipoteca.setUsername(rs.getString("username"));
vehiculoshipoteca.setIdreciboliberacion(rs.getInt("idreciboliberacion"));
vehiculoshipoteca.setFechahipotecaliberacion(rs.getDate("fechahipotecaliberacion"));
vehiculoshipoteca.setIdvehicleshipoteca(rs.getInt("idvehicleshipoteca"));
    }
    rs.close();
    psquery.close();
 return vehiculoshipoteca;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdvehiculo()
*/

public static List<Vehiculoshipoteca> findByIdvehiculo(Vehiculoshipoteca vehiculoshipoteca,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiculoshipoteca>();
      String sql = "select * from vehiculoshipoteca where idvehiculo='"+vehiculoshipoteca.getIdvehiculo()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculoshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiculoshipoteca vehiculoshipoteca2 = new Vehiculoshipoteca(
         rs.getLong("idvehiculo"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getDate("fechahipoteca"),rs.getInt("identidad"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fecha"),rs.getString("username"),rs.getInt("idreciboliberacion"),rs.getDate("fechahipotecaliberacion"),rs.getInt("idvehicleshipoteca"));
            
            
       list.add(vehiculoshipoteca2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByPlaca()
*/

public static List<Vehiculoshipoteca> findByPlaca(Vehiculoshipoteca vehiculoshipoteca,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiculoshipoteca>();
      String sql = "select * from vehiculoshipoteca where placa='"+vehiculoshipoteca.getPlaca()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculoshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiculoshipoteca vehiculoshipoteca2 = new Vehiculoshipoteca(
         rs.getLong("idvehiculo"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getDate("fechahipoteca"),rs.getInt("identidad"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fecha"),rs.getString("username"),rs.getInt("idreciboliberacion"),rs.getDate("fechahipotecaliberacion"),rs.getInt("idvehicleshipoteca"));
            
            
       list.add(vehiculoshipoteca2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdrecibo()
*/

public static List<Vehiculoshipoteca> findByIdrecibo(Vehiculoshipoteca vehiculoshipoteca,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiculoshipoteca>();
      String sql = "select * from vehiculoshipoteca where idrecibo='"+vehiculoshipoteca.getIdrecibo()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculoshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiculoshipoteca vehiculoshipoteca2 = new Vehiculoshipoteca(
         rs.getLong("idvehiculo"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getDate("fechahipoteca"),rs.getInt("identidad"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fecha"),rs.getString("username"),rs.getInt("idreciboliberacion"),rs.getDate("fechahipotecaliberacion"),rs.getInt("idvehicleshipoteca"));
            
            
       list.add(vehiculoshipoteca2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByFechahipoteca()
*/

public static List<Vehiculoshipoteca> findByFechahipoteca(Vehiculoshipoteca vehiculoshipoteca,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiculoshipoteca>();
      String sql = "select * from vehiculoshipoteca where fechahipoteca='"+vehiculoshipoteca.getFechahipoteca()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculoshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiculoshipoteca vehiculoshipoteca2 = new Vehiculoshipoteca(
         rs.getLong("idvehiculo"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getDate("fechahipoteca"),rs.getInt("identidad"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fecha"),rs.getString("username"),rs.getInt("idreciboliberacion"),rs.getDate("fechahipotecaliberacion"),rs.getInt("idvehicleshipoteca"));
            
            
       list.add(vehiculoshipoteca2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdentidad()
*/

public static List<Vehiculoshipoteca> findByIdentidad(Vehiculoshipoteca vehiculoshipoteca,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiculoshipoteca>();
      String sql = "select * from vehiculoshipoteca where identidad='"+vehiculoshipoteca.getIdentidad()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculoshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiculoshipoteca vehiculoshipoteca2 = new Vehiculoshipoteca(
         rs.getLong("idvehiculo"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getDate("fechahipoteca"),rs.getInt("identidad"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fecha"),rs.getString("username"),rs.getInt("idreciboliberacion"),rs.getDate("fechahipotecaliberacion"),rs.getInt("idvehicleshipoteca"));
            
            
       list.add(vehiculoshipoteca2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByActivo()
*/

public static List<Vehiculoshipoteca> findByActivo(Vehiculoshipoteca vehiculoshipoteca,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiculoshipoteca>();
      String sql = "select * from vehiculoshipoteca where activo='"+vehiculoshipoteca.getActivo()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculoshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiculoshipoteca vehiculoshipoteca2 = new Vehiculoshipoteca(
         rs.getLong("idvehiculo"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getDate("fechahipoteca"),rs.getInt("identidad"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fecha"),rs.getString("username"),rs.getInt("idreciboliberacion"),rs.getDate("fechahipotecaliberacion"),rs.getInt("idvehicleshipoteca"));
            
            
       list.add(vehiculoshipoteca2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdmunicipio()
*/

public static List<Vehiculoshipoteca> findByIdmunicipio(Vehiculoshipoteca vehiculoshipoteca,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiculoshipoteca>();
      String sql = "select * from vehiculoshipoteca where idmunicipio='"+vehiculoshipoteca.getIdmunicipio()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculoshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiculoshipoteca vehiculoshipoteca2 = new Vehiculoshipoteca(
         rs.getLong("idvehiculo"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getDate("fechahipoteca"),rs.getInt("identidad"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fecha"),rs.getString("username"),rs.getInt("idreciboliberacion"),rs.getDate("fechahipotecaliberacion"),rs.getInt("idvehicleshipoteca"));
            
            
       list.add(vehiculoshipoteca2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByFecha()
*/

public static List<Vehiculoshipoteca> findByFecha(Vehiculoshipoteca vehiculoshipoteca,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiculoshipoteca>();
      String sql = "select * from vehiculoshipoteca where fecha='"+vehiculoshipoteca.getFecha()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculoshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiculoshipoteca vehiculoshipoteca2 = new Vehiculoshipoteca(
         rs.getLong("idvehiculo"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getDate("fechahipoteca"),rs.getInt("identidad"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fecha"),rs.getString("username"),rs.getInt("idreciboliberacion"),rs.getDate("fechahipotecaliberacion"),rs.getInt("idvehicleshipoteca"));
            
            
       list.add(vehiculoshipoteca2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByUsername()
*/

public static List<Vehiculoshipoteca> findByUsername(Vehiculoshipoteca vehiculoshipoteca,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiculoshipoteca>();
      String sql = "select * from vehiculoshipoteca where username='"+vehiculoshipoteca.getUsername()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculoshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiculoshipoteca vehiculoshipoteca2 = new Vehiculoshipoteca(
         rs.getLong("idvehiculo"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getDate("fechahipoteca"),rs.getInt("identidad"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fecha"),rs.getString("username"),rs.getInt("idreciboliberacion"),rs.getDate("fechahipotecaliberacion"),rs.getInt("idvehicleshipoteca"));
            
            
       list.add(vehiculoshipoteca2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdreciboliberacion()
*/

public static List<Vehiculoshipoteca> findByIdreciboliberacion(Vehiculoshipoteca vehiculoshipoteca,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiculoshipoteca>();
      String sql = "select * from vehiculoshipoteca where idreciboliberacion='"+vehiculoshipoteca.getIdreciboliberacion()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculoshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiculoshipoteca vehiculoshipoteca2 = new Vehiculoshipoteca(
         rs.getLong("idvehiculo"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getDate("fechahipoteca"),rs.getInt("identidad"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fecha"),rs.getString("username"),rs.getInt("idreciboliberacion"),rs.getDate("fechahipotecaliberacion"),rs.getInt("idvehicleshipoteca"));
            
            
       list.add(vehiculoshipoteca2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByFechahipotecaliberacion()
*/

public static List<Vehiculoshipoteca> findByFechahipotecaliberacion(Vehiculoshipoteca vehiculoshipoteca,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiculoshipoteca>();
      String sql = "select * from vehiculoshipoteca where fechahipotecaliberacion='"+vehiculoshipoteca.getFechahipotecaliberacion()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculoshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiculoshipoteca vehiculoshipoteca2 = new Vehiculoshipoteca(
         rs.getLong("idvehiculo"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getDate("fechahipoteca"),rs.getInt("identidad"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fecha"),rs.getString("username"),rs.getInt("idreciboliberacion"),rs.getDate("fechahipotecaliberacion"),rs.getInt("idvehicleshipoteca"));
            
            
       list.add(vehiculoshipoteca2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdvehicleshipoteca()
*/

public static List<Vehiculoshipoteca> findByIdvehicleshipoteca(Vehiculoshipoteca vehiculoshipoteca,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiculoshipoteca>();
      String sql = "select * from vehiculoshipoteca where idvehicleshipoteca='"+vehiculoshipoteca.getIdvehicleshipoteca()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculoshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiculoshipoteca vehiculoshipoteca2 = new Vehiculoshipoteca(
         rs.getLong("idvehiculo"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getDate("fechahipoteca"),rs.getInt("identidad"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fecha"),rs.getString("username"),rs.getInt("idreciboliberacion"),rs.getDate("fechahipotecaliberacion"),rs.getInt("idvehicleshipoteca"));
            
            
       list.add(vehiculoshipoteca2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* locateByParameters()
*/

public static List<Vehiculoshipoteca> locateByParameters(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiculoshipoteca>();
  String sql = "select * from vehiculoshipoteca";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      int i = 0;
      while (it.hasNext()) {
          if (i != 0){
            sb.append(" and ");
         }
         i++;
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"= '"+  e.getValue()+"'");
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculoshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiculoshipoteca vehiculoshipoteca2 = new Vehiculoshipoteca(
         rs.getLong("idvehiculo"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getDate("fechahipoteca"),rs.getInt("identidad"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fecha"),rs.getString("username"),rs.getInt("idreciboliberacion"),rs.getDate("fechahipotecaliberacion"),rs.getInt("idvehicleshipoteca"));
            
            
       list.add(vehiculoshipoteca2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* Double fFunc(String funcion, String campo)
*/



public static Double func(String funcion, String campo) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from vehiculoshipoteca";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculoshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0.0;
}


/**
*
* Double func(String funcion, String campo,String where)
*/



public static Double func(String funcion, String campo, String where) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from vehiculoshipoteca where "+where +" ";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculoshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0.0;
}


/**
*
* count()
*/



public static Integer count() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from vehiculoshipoteca";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculoshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0;
}


/**
*
* count(String sqlquery)
*/



public static Integer count(String sqlquery) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from vehiculoshipoteca where  " + sqlquery +"";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculoshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0;
}


/**
*
* query()
*/

public static List<Vehiculoshipoteca> query(String query,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<Vehiculoshipoteca>();
  String sql = "select * from vehiculoshipoteca where " + query +"";
  if (query == null || query.equals("")) {
  return null;
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculoshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiculoshipoteca vehiculoshipoteca2 = new Vehiculoshipoteca(
         rs.getLong("idvehiculo"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getDate("fechahipoteca"),rs.getInt("identidad"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fecha"),rs.getString("username"),rs.getInt("idreciboliberacion"),rs.getDate("fechahipotecaliberacion"),rs.getInt("idvehicleshipoteca"));
            
            
       list.add(vehiculoshipoteca2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* getListRecords()
*/

public static List<Vehiculoshipoteca> getListRecords(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      list = new ArrayList<Vehiculoshipoteca>();
  String sql = "select * from vehiculoshipoteca";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      while (it.hasNext()) {
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"="+  e.getValue());
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculoshipoteca" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
       
        Vehiculoshipoteca vehiculoshipoteca2 = new Vehiculoshipoteca(
         rs.getLong("idvehiculo"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getDate("fechahipoteca"),rs.getInt("identidad"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fecha"),rs.getString("username"),rs.getInt("idreciboliberacion"),rs.getDate("fechahipotecaliberacion"),rs.getInt("idvehicleshipoteca"));
            
            
       list.add(vehiculoshipoteca2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
 }


}
